const express = require('express');
const app = express();
const mongoose = require('mongoose');

let dbUrl = 'mongodb://localhost:27017/db-api';
mongoose.Promise = global.Promise;
mongoose.connect(dbUrl);
const db = mongoose.connection;
db.once('open', function() {
	console.log('mongodb connect success');
});

const bodyParser = require('body-parser');
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }));
// parse application/json
app.use(bodyParser.json());

let routes = require('./routes.js');
routes(app);

app.listen(4000, function() {
	console.log('running on port 4000');
	console.log('http://localhost:4000', 'http://172.24.8.15:4000');
});
